Xbasic

REGEX_MATCH Function

Syntax

Result_Flag as L = REGEX_MATCH( text as c , RegExp as c [,options as c])

Arguments

Result_Flag

.T. (TRUE) if the Expression matched the Text ; otherwise .F. (FALSE).

text

The character string to examine. The parentheses characters " ( " and " ) " have special meaning. If present, they enclose a regular expression argument. If you want parentheses characters to be part of the text, you must precede them with " \ " characters.

RegExp

A regular expression that contains a search argument. Refer to Regular Expressions for detailed information.

options

Optional. Default = "S". Specify which compatibility with a common implementation. The flags for Emacs, Awk, Grep, Egrep and Sed conventions allow the pattern to follow the conventions of those utilities (which have slightly different variants regarding what is escaped and what is not escaped).

"I"

Ignore case

"E"

Follow Emacs conventions

"A"

Follow Awk conventions

"G"

Follow Grep conventions

"EG"

Follow Egrep conventions

"S"

Follow Sed conventions

"X"

Extended (similar to Awk but no need to escape '' inside of [])

Description

Return TRUE if regular expression tags match.

Discussion

The REGEX_MATCH() function searches Text for a match to Search_Expresssion returns .T. (TRUE) or .F. (FALSE).

The Case Insensitive Flag

The following examples show the effect of the case insensitive flag. Since F is capitalized, the string does not match.

? regex_match("Fred","[a-z]+")
= .F.

Looking for capitals and lowercase explicitly matches.

? regex_match("Fred","[A-Za-z]+")
= .T.
' Or, alternatively, there is a flag for 'case does not matter' - which is
helpful
' if you have a much longer string you are trying to match (i.e. - HTML tags)
? regex_match("Fred","[a-z]+","i")
= .T.

Or, alternatively, there is a flag for 'case does not matter', which is helpful if you have a much longer string you are trying to match (i.e. HTML tags).

? regex_match("Fred","[a-z]+","i")
= .T.

Example

In the first example, there are two arguments: name and ([a-z]+). Note how the first function argument uses parentheses to identify the regular expression argument. The second function argument includes parentheses in the regular expression argument. The square brackets have special meaning, as Does the plus "+" sign. This function asks: Does the string name contain one or more alphabetic characters and only alphabetic characters. The answer is .T. (TRUE).

? regex_match("(name)","\([a-z]+\)")
= .T.

In the second example the two arguments are: (name) and ([a-z]+). Both function arguments include parentheses in the regular expression argument. This function asks: Does the string name contain one or more alphabetic characters and only alphabetic characters. The answer is .F. (FALSE), because parentheses are not alphabetic characters.

? regex_match("\(name\)","\([a-z]+\)")
= .F.

In the third example the two arguments are: [name] and ([a-z]+). This function asks: Does the string [name] contain one or more alphabetic characters and only alphabetic characters. The answer is .F. (FALSE), because square brackets are not alphabetic characters.

? regex_match("[name]","\([a-z]+\)")
= .F.

In the fourth example the two arguments are: 1 and ([a-z]+). This function asks: Does the string 1 contain one or more alphabetic characters and only alphabetic characters. The answer is .F. (FALSE), because numbers are not alphabetic characters.

? regex_match("(1)","\([a-z]+\)")
= .F.

Dealing with matching High Order Characters

High order characters can be included as escaped unicode if you use the "X" or "A" option. This is the best way to handle expressions that are used on both the client and the server, since javascript expects high order characters in regex expressions to be escaped.

? regex_match("&#xE1","[a-z\u00E1]","X")
.T.

See Also